<template>
    <div>
      <h2>测试axios实例</h2>
      <ul>
        <li v-for="issue in issues" :key="issue.id">
          <span>{{issue.title}}</span>
        </li>
      </ul>
      <ul>
        <li v-for="user in users" :key="user.id">
          <img :src="user.avatar_url" width="100" height="100">
        </li>
      </ul>
    </div>
</template>

<script>
    import axios from 'axios'
    //全局配置
    axios.defaults.baseURL="https://api.a.com";
    //添加拦截器

    export default {
        name: "testGet",
        data(){
          return {
            issues:[],
            users:[]
          }
        },
        async mounted(){
          //配置优先级
          var axiosIns = axios.create({
            baseURL:"https://api.b.com",
            timeout:100000
          })

          //添加拦截器
          // 添加请求拦截器
          axiosIns.interceptors.request.use(function (config) {
            // 在发送请求之前做些什么
            config.baseURL="https://api.github.com";
            return config;
          });

        // 添加响应拦截器
          axiosIns.interceptors.response.use(function (response) {
            // 对响应数据做点什么
            return response.data;
          }, function (error) {
            // 对响应错误做点什么
            return Promise.reject(error);
          });


          var body = await axiosIns({
            baseURL:"https://api.c.com",
            url: '/repos/betterDamu/sh_200318/issues'
          })

          console.log(body);

          //axios实例
          /*var body1 = await axiosIns({
            url: '/repos/betterDamu/sh_200318/issues'
          })

          var body2 = await axiosIns({
            url:"/search/users",
            params:{
              q:"damu"
            }
          })

          console.log(body1);

          this.issues = body1.data;
          this.users = body2.data.items;*/
        }
    }
</script>

<style scoped>

</style>
